package com.bjsxt.shop.back.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.shop.common.util.ConstantFinalUtil;
import com.bjsxt.shop.common.util.HttpUtil;
import com.bjsxt.shop.serviceApi.pojo.AAdmins;

@Controller
public class NoLoginController
{
	/**
	 * 商城後臺管理員退出方法
	 * @param request
	 * @return
	 */
	@RequestMapping("/loginOut")
	public String loginOut(HttpServletRequest request)
	{
		/*先將用戶中心退出*/
		HttpSession session = request.getSession();
		AAdmins admin = (AAdmins) session.getAttribute("admin");
		String token = admin.getToken();
		Map<String,String> paramsMap = new HashMap<String,String>();
		paramsMap.put("token", token);
		HttpUtil httpUtil = new HttpUtil();
		/*請求用戶中心接口，退出當前用戶*/
		httpUtil.methodPost(ConstantFinalUtil.BUNDLE.getString("users.center.logoutUrl"), Collections.EMPTY_MAP, paramsMap);
		/*商城後臺退出*/
		session.removeAttribute("admin");
		return "loginOut";
	}
}
